package com.baseDemo.web.service.addresslist.impl;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;

import com.baseDemo.web.dao.addresslist.AddressListEntityDao;
import com.baseDemo.web.entity.AddressListEntity;
import com.baseDemo.web.entity.UserEntity;
import com.baseDemo.web.server.SystemServer;
import com.baseDemo.web.service.addresslist.AddressListService;
import com.share.hibernate.baseDaoSupport.PageUtil;
import com.share.service.baseServiceSupport.impl.BaseServiceSupport;
@Service
public class AddressListServiceImpl extends BaseServiceSupport<AddressListEntity> implements AddressListService{
	@Resource
	private AddressListEntityDao addressListEntityDao;
	@Resource PageUtil pageUtil;
	@Override
	public PageUtil getListForPageToJson(Integer start, Integer limit,HttpServletRequest request) {
		UserEntity user=(UserEntity)request.getSession().getAttribute(SystemServer.getInstance().get("USERSESSION").toString());
		if(user!=null){
			Integer rowTotal = addressListEntityDao.getPageTotal(user.getId());
			pageUtil.setTotal(rowTotal);
			List<AddressListEntity> list = addressListEntityDao.findbyUser(start, limit, user.getId());
			pageUtil.setEntityList(list);
			return pageUtil;
		}
		return null;
	}
	@Override
	public String addAddressList(AddressListEntity addressListEntity,
			HttpServletRequest request) {
		UserEntity user=(UserEntity)request.getSession().getAttribute(SystemServer.getInstance().get("USERSESSION").toString());
		if(user!=null){
			addressListEntity.setUser(user);
			addressListEntityDao.save(addressListEntity);
		}
		return String.valueOf(0);
	}

}
